package service;

import dao.Imp_Sysmanage;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
@WebServlet("/system_loginServlet")
public class System_LoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        String name = req.getParameter("usename");
        String password = req.getParameter("password");
        Imp_Sysmanage sysmanage=new Imp_Sysmanage();
        boolean login=sysmanage.sysmanagerlogin(name,password);
        if (!login) {
            req.setAttribute("login_fail","用户名或密码错误");
            req.getRequestDispatcher("/system_login.jsp").forward(req,resp);
        }
        else {
            resp.sendRedirect(req.getContextPath()+"/systemNote.jsp");
        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
